In [1]:
from pearce.emulator import OriginalRecipe, ExtraCrispy
from pearce.mocks import cat_dict
import numpy as np
from os import path

In [2]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

In [3]:
training_file = '/u/ki/swmclau2/des/PearceRedMagicWpCosmo2.hdf5'

em_method = 'gp'
split_method = 'random'

In [4]:
a = 1.0
z = 1.0/a - 1.0

In [5]:
fixed_params = {'z':z, 'r': 0.19118072}
n_leaves, n_overlap = 50, 1 emu = ExtraCrispy(training_file, n_leaves, n_overlap, split_method, method = em_method, fixed_params=fixed_params, custom_mean_function = None, downsample_factor = 1.0)
[2.00099536e-02 3.01364367e+12 3.85037773e+08 3.26521386e+00 1.04532425e+10 1.08309365e+02 8.93157118e+00 3.42147512e+00 2.42353221e+00 2.13755406e+02 1.39057797e+01 4.87435453e-01 3.08648691e+03 6.96469887e+00]
[5.24986000e-02 2.86352579e+01 5.84173262e+15 3.38592088e+01 3.51654400e-01 1.86694193e+08 1.53565585e+00 8.97636037e-01 9.93547405e-01 1.20239382e+09 4.04677604e+00 1.17545119e-01 3.81620957e+01 1.00624705e+00]

In [7]:
emu = OriginalRecipe(training_file, method = em_method, fixed_params=fixed_params, downsample_factor=0.12)#,
                    #hyperparams = {'n_estimators': 500,
                    #              'max_depth': 5})


/u/ki/swmclau2/.local/lib/python2.7/site-packages/pearce/emulator/emu.py:253: UserWarning: WARNING: NaN detected. Skipped 704 points in training data.
  warnings.warn('WARNING: NaN detected. Skipped %d points in training data.' % (num_skipped))

In [8]:
emu.scale_bin_centers


Out[8]:
array([ 0.09581734,  0.13534558,  0.19118072,  0.27004994,  0.38145568,
        0.53882047,  0.76110414,  1.07508818,  1.51860241,  2.14508292,
        3.03001016,  4.28000311,  6.04566509,  8.53972892, 12.06268772,
       17.0389993 , 24.06822623, 33.99727318])

In [9]:
#print emu.x.shape
#print emu.downsample_x.shape
if hasattr(emu, "_emulators"):
    print emu._emulators[0]._x.shape
else:
    print emu._emulator._x.shape


(2304, 13)

In [10]:
emu._ordered_params


Out[10]:
OrderedDict([('ombh2', (0.02066455, 0.02371239)),
             ('omch2', (0.1012181, 0.13177679999999997)),
             ('w0', (-1.399921, -0.5658486)),
             ('ns', (0.9278462, 0.9974495999999999)),
             ('ln10As', (3.0009, 3.179424)),
             ('H0', (61.69472, 74.76751999999999)),
             ('Neff', (2.62125, 4.27875)),
             ('logM1', (13.0, 15.0)),
             ('logMmin', (11.5, 13.5)),
             ('f_c', (0.01, 0.5)),
             ('logM0', (12.0, 16.0)),
             ('sigma_logM', (0.05, 0.6)),
             ('alpha', (0.8, 1.2))])
x, y, y_pred = emu.goodness_of_fit(training_file, statistic = 'log_frac')
x, y, y_pred
N = 25 for _y, yp in zip(y[:N], y_pred[:N]): #plt.plot(emu.scale_bin_centers , (_y - yp)/yp ,alpha = 0.3, color = 'b') plt.plot(emu.scale_bin_centers, _y, alpha = 0.3, color = 'b') plt.plot(emu.scale_bin_centers, yp, alpha = 0.3, color = 'r') plt.loglog();

In [11]:
emu.train_metric()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-50f0d7bb9f64> in <module>()
----> 1 emu.train_metric()

/u/ki/swmclau2/.local/lib/python2.7/site-packages/pearce/emulator/emu.pyc in train_metric(self, p0, **kwargs)
   1245         #   [(np.log(0.01), np.log(10)) for i in xrange(ndim+1)],options={'maxiter':50})
   1246 
-> 1247         self._emulator.kernel[:] = results.x
   1248         self._emulator.recompute()
   1249         # self.metric = np.exp(results.x)

/u/ki/swmclau2/.conda/envs/hodemulator/lib/python2.7/site-packages/george/modeling.pyc in __setitem__(self, name_or_index, value)
    149 
    150     def __setitem__(self, name_or_index, value):
--> 151         return self.set_parameter(self._get_name(name_or_index), value)
    152 
    153     @property

/u/ki/swmclau2/.conda/envs/hodemulator/lib/python2.7/site-packages/george/modeling.pyc in set_parameter(self, name, value)
    463     def set_parameter(self, name, value):
    464         self.dirty = True
--> 465         return self._apply_to_parameter("set_parameter", name, value)
    466 
    467     def log_prior(self):

/u/ki/swmclau2/.conda/envs/hodemulator/lib/python2.7/site-packages/george/modeling.pyc in _apply_to_parameter(self, func, name, *args)
    433 
    434     def _apply_to_parameter(self, func, name, *args):
--> 435         comp = name.split(":")
    436         model_name = comp[0]
    437         if model_name not in self.models:

AttributeError: 'slice' object has no attribute 'split'

In [ ]:
%%timeit
#truth_file = '/u/ki/swmclau2/des/PearceRedMagicWpCosmoTest.hdf5'
gof = emu.goodness_of_fit(training_file, N = 100, statistic = 'log_frac')

In [ ]:
gof = emu.goodness_of_fit(training_file, N = 1000, statistic = 'log_frac')

In [ ]:
print gof.mean(axis =0)

In [ ]:
plt.plot(emu.scale_bin_centers, np.abs(gof.mean(axis = 0)) )
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.01)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.05)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.1)


plt.loglog();

In [ ]:
plt.plot(emu.scale_bin_centers, np.abs(gof.T),alpha = 0.1, color = 'b')
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.01, lw = 2, color = 'k')
plt.loglog();

In [ ]: